﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Entity = SoTaiChinh.Library.Entity;
using Business = SoTaiChinh.Library.Business;
using Common = SoTaiChinh.Library.Common;

public partial class templates_client_usercontrols_menu_vertical : System.Web.UI.UserControl
{
    Common.Algorithm.Validators validator = new Common.Algorithm.Validators();
    DataTable dsDanhMucCha = new DataTable();
    DataTable dsDanhMucCon1 = new DataTable();
    Business.DanhMuc business = new Business.DanhMuc();
    Entity.DanhMuc entityDanhMucCha = new Entity.DanhMuc();
    Entity.DanhMuc entityDanhMucCon1 = new Entity.DanhMuc();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDanhMuc();
        }
    }
    protected void LoadDanhMuc()
    {
        try
        {
            string str = "";
            dsDanhMucCha = business.SelectTraiCap();
            if (dsDanhMucCha.Rows.Count > 0)
            {
                for (int i = 0; i < dsDanhMucCha.Rows.Count; i++)
                {
                    // Kiểm tra xem có con hay không để thêm thuộc tính css cho link
                    string css = "";
                    entityDanhMucCon1.DanhMucCha = Convert.ToInt32(dsDanhMucCha.Rows[i]["Id"].ToString());
                    dsDanhMucCon1 = business.SelectByDanhMucCha(entityDanhMucCon1);
                    if (dsDanhMucCon1.Rows.Count > 0)
                    {
                        css = "submenu";
                    }
                    str += "<li> ";
                    str += "<img src=\"../templates/client/images/iconsubmenu.png\" style=\"margin:8px 5px 0px 5px\"/>";
                    str += "<a href=\"list-news.aspx?action=cate&chuyenmuc=" + dsDanhMucCha.Rows[i]["Id"].ToString() + "\" name=\"submenu\" class=\"" + css + "\">" + dsDanhMucCha.Rows[i]["Ten"].ToString() + "</a>";
                    if (dsDanhMucCon1.Rows.Count > 0)
                    {
                        str += " <ul>";
                        for (int j = 0; j < dsDanhMucCon1.Rows.Count; j++)
                        {
                            if (dsDanhMucCon1.Rows[j]["Ten"].ToString() == "Hình ảnh")
                            {
                                str += "<li> <img src=\"../templates/client/images/row_3.gif\" style=\"margin:15px 5px 0px 5px\"/><a href=\"hinhanh.aspx?action=cate&chuyenmuc=" + dsDanhMucCon1.Rows[j]["Id"].ToString() + "\">Hình ảnh</a> </li>";
                            }
                            else if (dsDanhMucCon1.Rows[j]["Ten"].ToString() == "Video")
                            {
                                str += "<li> <img src=\"../templates/client/images/row_3.gif\" style=\"margin:15px 5px 0px 5px\"/><a href=\"video.aspx?action=cate&chuyenmuc="+ dsDanhMucCon1.Rows[j]["Id"].ToString() +"\">Video</a> </li>";
                            }
                            else
                            {
                                str += "<li> <img src=\"../templates/client/images/row_3.gif\" style=\"margin:15px 5px 0px 5px\"/><a href=\"list-news.aspx?action=cate&chuyenmuc=" + dsDanhMucCon1.Rows[j]["Id"].ToString() + "\">" + dsDanhMucCon1.Rows[j]["Ten"].ToString() + "</a> </li>";
                            }
                        }
                        str+= " </ul>";
                    }
                    str += " </li>";
                }
            }
            menuList.InnerHtml = str;
        }
        catch(Exception ex)
        {
            throw ex;
        }
    }
}
